<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="标题" prop="headline">
        <el-input
          v-model="queryParams.headline"
          placeholder="请输入标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分类" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择分类" clearable>
          <el-option
            v-for="dict in dict.type.long_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="start">
        <el-select v-model="queryParams.start" placeholder="请选择审核状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_notice_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="上传时间" prop="time">
        <el-date-picker clearable
                        v-model="queryParams.time"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择上传时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核时间" prop="end">
        <el-date-picker clearable
                        v-model="queryParams.end"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择审核时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:video:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:video:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:video:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:video:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['system:video:daoru']"
        >导入</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>







    <el-table v-loading="loading" :data="videoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="序号" align="center" prop="id"/>
      <el-table-column label="ID" align="center" prop="contentId"/>
      <el-table-column label="标题" align="center" prop="headline"/>
      <el-table-column label="封面" align="center" prop="cover" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.cover" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="直播" align="center" prop="" width="100">
        <a href="https://live.douyin.com/208823316033"><span style="background-color: #004d8c ;color: #FFFFFF">播放</span> </a>
      </el-table-column>
<!--      <el-table-column label="视频" align="center" prop="mv"/>-->
      <el-table-column label="分类" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.long_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="上传者" align="center" prop="uploader"/>
      <el-table-column label="手机号" align="center" prop="ipone"/>
      <el-table-column label="审核状态" align="center" prop="start">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_notice_status" :value="scope.row.start"/>
        </template>
      </el-table-column>
      <el-table-column label="审核管理员" align="center" prop="audit"/>
      <el-table-column label="上传时间" align="center" prop="time" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核时间" align="center" prop="end" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.end, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>


      <el-table-column
        prop="status"
        label="状态"
      >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.status"
            style="width: 250px"
            active-color="#13ce66"
            inactive-color="#ff4949"
            :active-value=1
            :inactive-value=2
            @change="changestatues(scope.row.id,scope.row.status)"
          >

          </el-switch>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="primary"
                     size="mini"
                     v-if="scope.row.start==1"
                     @click="xq(scope.row.longId)"
          >详情
          </el-button>

          <el-button type="primary"
                     size="mini"
                     v-if="scope.row.start==1"
                     @click="handleUpdate(scope.row)"
          >修改
          </el-button>


          <el-button type="primary"
                     size="mini"
                     v-if="scope.row.start==2"
                     @click="shen(scope.row)"
          >审核
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--    详情-->

        <el-dialog title="" :visible.sync="dialogTableVisible">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="视频数据" name="first">
        <el-table :data="gridData">
          <el-table-column property="liulan" label="浏览量" width="150"></el-table-column>
          <el-table-column property="zanage" label="点赞数" width="200"></el-table-column>
          <el-table-column property="shouage" label="收藏数"></el-table-column>
          <el-table-column property="fenage" label="分享数"></el-table-column>
          <el-table-column property="xiage" label="下载数"></el-table-column>
          <el-table-column property="pingage" label="评论数"></el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="付费列表" name="second">
        <el-table :data="fu">
          <el-table-column property="fid" label="编号" width="150"></el-table-column>
          <el-table-column property="ftype" label="付费类型" width="200"></el-table-column>
          <el-table-column property="price" label="价格"></el-table-column>
          <el-table-column property="status" label="付费状态">
            <template slot-scope="scope">
              {{scope.row.status==1?'成功':'未付费'}}
            </template>
          </el-table-column>
          <el-table-column property="ren" label="购买人"></el-table-column>
          <el-table-column property="ipone" label="手机号"></el-table-column>
          <el-table-column property="time" label="购买时间"></el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>
        </el-dialog>



    <!-- 添加或修改长视频管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="标题" prop="headline">
          <el-input v-model="form.headline" placeholder="请输入,限制30字符"/>
        </el-form-item>


        <el-form-item prop="cover" label="封面" width="100">
          <image-upload v-model="form.cover" />
        </el-form-item>
<!--        <el-form-item prop="url" label="商品图片" width="100">-->
<!--          <el-upload-->
<!--            :action="BASE_API +'/goods/fileUpload'"-->
<!--            list-type="picture-card"-->
<!--            :on-preview="handlePictureCardPreview"-->
<!--            :on-remove="handleRemove"-->
<!--            :on-success="handleUploadSuccess"-->
<!--            v-model="form.cover">-->
<!--            <i class="el-icon-plus"></i>-->
<!--          </el-upload>-->
<!--          <el-dialog visible.sync="dialogVisible">-->
<!--            <img width="100%" :src="dialogImageUrl" alt="">-->
<!--          </el-dialog>-->
<!--        </el-form-item>-->


        <el-form-item label="视频" prop="mv">
          <el-input v-model="form.mv" placeholder="请输入视频"/>
        </el-form-item>
        <el-form-item label="分类" prop="type">
          <el-select v-model="form.type" placeholder="请选择分类">
            <el-option
              v-for="dict in dict.type.long_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="信息描述" prop="ms">
          <el-input v-model="form.ms" placeholder="请输入,限制30字符"/>
        </el-form-item>

        <!--        <br><br><br><h2>审核信息</h2>-->

        <!--        <el-form-item label="审核意见">-->
        <!--          <el-radio-group v-model="form.start">-->
        <!--            <el-radio label="1">通过</el-radio>-->
        <!--            <el-radio label="2">不通过</el-radio>-->
        <!--          </el-radio-group>-->
        <!--        </el-form-item>-->


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


<!--    审核-->
    <el-dialog :title="title2" :visible.sync="open2" width="500px" append-to-body>
      <el-form ref="form" :model="form2" :rules="rules" label-width="80px">

        <el-form-item label="标题" prop="headline">
          <el-input v-model="form2.headline" placeholder="请输入,限制30字符"/>
        </el-form-item>

        <el-form-item prop="cover" label="封面" width="100">
          <image-upload v-model="form2.cover" />
        </el-form-item>


<!--        <el-form-item prop="url" label="商品图片" width="100">-->
<!--          <el-upload-->
<!--            :action="BASE_API +'/goods/fileUpload'"-->
<!--            list-type="picture-card"-->
<!--            :on-preview="handlePictureCardPreview"-->
<!--            :on-remove="handleRemove"-->
<!--            :on-success="handleUploadSuccess"-->
<!--            v-model="updateForm.url">-->
<!--            <i class="el-icon-plus"></i>-->
<!--          </el-upload>-->
<!--          <el-dialog visible.sync="dialogVisible">-->
<!--            <img width="100%" :src="dialogImageUrl" alt="">-->
<!--          </el-dialog>-->
<!--        </el-form-item>-->


        <el-form-item label="视频" prop="mv">
          <el-input v-model="form2.mv" placeholder="请输入视频"/>
        </el-form-item>
        <el-form-item label="分类" prop="type">
          <el-select v-model="form2.type" placeholder="请选择分类">
            <el-option
              v-for="dict in dict.type.long_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="信息描述" prop="ms">
          <el-input v-model="form2.ms" placeholder="请输入,限制30字符"/>
        </el-form-item>

        <br><br><br>
        <h2>审核信息</h2>

        <el-form-item label="审核意见">
          <el-radio-group v-model="form2.start">
            <el-radio label="1">通过</el-radio>
            <el-radio label="2">不通过</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="备注">
          <el-input type="textarea" v-model="form2.ms"></el-input>
        </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm2">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>




    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open3" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open3 = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listVideo, getVideo, delVideo, addVideo, updateVideo, getVideoxq,getdatefufei,getchangestatues} from "@/api/system/video";
import { getToken } from "@/utils/auth";
export default {
  name: "Video",
  dicts: ['sys_notice_status', 'long_type'],
  data() {
    return {

      upload: {
        // 是否显示弹出层（用户导入）
        open3: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/video/daoru" // todo
      },

      activeName: 'second',
      // 详情弹框
      dialogTableVisible: false,
      // 详情
      gridData: [],
      // 图片路径
      // 图片
      dialogImageUrl: '',
      videoUrl: '',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 长视频管理表格数据
      videoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        headline: null,
        type: null,
        start: null,
        time: null,
        end: null,
      },
      fu:[],
      open2: false,
      // 表单参数
      form: {
        headline: null,
        cover: null,
        uploader: null,
        ipone: null,
        start: null,
        audit: null,
        time: null,
        end: null,
        longId: null,
        status: null,
        ms: null,
      },
      form2: {
        headline: null,
        cover: null,
        uploader: null,
        ipone: null,
        start: null,
        audit: null,
        time: null,
        end: null,
        longId: null,
        status: null,
        ms: null,
      },
      title2: '',
      // 表单校验
      rules: {
        type: [
          {required: true, message: "分类不能为空", trigger: "change"}
        ],
        start: [
          {required: true, message: "审核状态不能为空", trigger: "change"}
        ],
      },
      xid:0
    };
  },
  created() {
    this.getList();
  },

  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    xq(longId) {
      getVideoxq(longId).then(response => {
        this.dialogTableVisible = true;
        this.gridData = response.data;
        this.xid = this.gridData[0].id;
        this.fufei();
      })

    },

    fufei(){
      getdatefufei(this.xid).then(response => {
        this.fu= response.data;
        console.log(this.fu)
      })
    },



    /** 查询长视频管理列表 */
    getList() {
      this.loading = true;
      listVideo(this.queryParams).then(response => {
        this.videoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        contentId: null,
        headline: null,
        cover: null,
        mv: null,
        type: null,
        uploader: null,
        ipone: null,
        start: null,
        audit: null,
        time: null,
        end: null,
        status: null,
        longId: null,
      };
      this.resetForm("form");
    },
    // 重置审核表单
    reset2() {
      this.form2 = {
        id: null,
        contentId: null,
        headline: null,
        cover: null,
        mv: null,
        type: null,
        uploader: null,
        ipone: null,
        start: null,
        audit: null,
        time: null,
        end: null,
        status: null,
        longId: null,
        ms: null,

      };
      this.resetForm("form2");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },

    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleUploadSuccess1(response) {
      // 在这里可以从 response 中获取上传成功后的 URL
      this.videoUrl = response.data
    },
    handleUploadSuccess(response) {
      // 在这里可以从 response 中获取上传成功后的 URL
      this.form.cover = response.data;
      console.log('上传成功', response);
    },
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加长视频管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getVideo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改长视频管理";
      });
    },

    // 审核
    shen(row) {
      this.reset2();
      const id = row.id || this.ids
      getVideo(id).then(response => {
        this.form2 = response.data;
        this.open2 = true;
        this.title2 = "审核";
      });
    },

    /** 审核提交按钮 */
    submitForm2() {
      updateVideo(this.form2).then(response => {
        this.$modal.msgSuccess("审核成功");
        this.open2 = false;
        this.getList();
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateVideo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addVideo(this.form).then(response => {
              this.dialogImageUrl = this.form.cover
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除长视频管理编号为"' + ids + '"的数据项？').then(function () {
        return delVideo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/video/export', {
        ...this.queryParams
      }, `video_${new Date().getTime()}.xlsx`)
    },

    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "编号导入"; // todo
      this.upload.open3 = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('system/video/daoru', {
      }, `stu_base_template_${new Date().getTime()}.xlsx`)  // todo
    },
// 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
// 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
// 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },


    // changestatues(id,status){
    //   getchangestatues(id,status).then(response => {
    //      if(response.date.status== 2){
    //        this.$modal.msgSuccess("已关闭");
    //      }else {
    //        this.$modal.msgSuccess("已开启");
    //      }
    //    this.getList();
    //   })
    // }

  },


};
</script>



